﻿
cmake_minimum_required(VERSION 3.2)
project(zhilaiSDK_demo VERSION 1.0.10.210430)

# project version
MESSAGE("generating project [ " ${PROJECT_NAME} " ]")
MESSAGE("version: " ${PROJECT_VERSION})

# add include path
include_directories(
    ${SRC_DIR}
    ${PROJECT_SOURCE_DIR}
)
link_directories(
    ${PROJECT_SOURCE_DIR}/zhilaiSDK
)

# qt5 setttings
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(Qt5_DIR "D:\\Qt\\Qt5.10.1\\5.10.1\\msvc2015\\lib\\cmake\\Qt5")
find_package(Qt5 COMPONENTS Core Widgets Concurrent REQUIRED LinguistTools)
include_directories(${Qt5Widgets_INCLUDE_DIRS})

# translation
if (QT_TS_FILE)
    set_source_files_properties(${QT_TS_FILE} PROPERTIES OUTPUT_LOCATION ${CMAKE_BINARY_DIR})
    add_custom_command(OUTPUT ${QT_TS_FILE} PRE_BUILD
        COMMAND ${Qt5_LUPDATE_EXECUTABLE} -target-language zh_CN ${PROJECT_SOURCE_DIR} -ts ${QT_TS_FILE}
        COMMAND ${Qt5_LRELEASE_EXECUTABLE} ${QT_TS_FILE} -qm ${CMAKE_BINARY_DIR}/${PROJECT_NAME}_zh_CN.qm
    )
endif()

# add include path
include_directories(${PROJECT_BINARY_DIR})

include(${SRC_DIR}/cmake/version.cmake)

link_directories(${PROJECT_SOURCE_DIR}/zhilaiSDK)

set(SRC_SOURCES
    "main.cpp"
    "CTestingWnd.cpp"
    "CDialog.cpp"
)
set(SRC_HEADERS
    "CTestingWnd.h"
    "CDialog.h"
)

add_executable(${PROJECT_NAME} 
    ${SRC_SOURCES}  
    ${SRC_HEADERS}
)
target_link_libraries(${PROJECT_NAME} 
    zhilaiSDK 
    Qt5::Core Qt5::Widgets Qt5::Concurrent
)

# Remove the console of gui program
if(WIN32)
    if(MSVC)
        set_target_properties(${PROJECT_NAME} PROPERTIES
            WIN32_EXECUTABLE YES
            LINK_FLAGS "/ENTRY:mainCRTStartup"
        )
    elseif(CMAKE_COMPILER_IS_GNUCXX)
            SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows") # Not tested
    else()
        message(SEND_ERROR "You are using an unsupported Windows compiler! (Not MSVC or GCC)")
    endif(MSVC)
elseif(APPLE)
    set_target_properties(${target} PROPERTIES
        MACOSX_BUNDLE YES
    )
elseif(UNIX)
    # Nothing special required
else()
    message(SEND_ERROR "You are on an unsupported platform! (Not Win32, Mac OS X or Unix)")
endif(WIN32)
